#include <vga.h>
#include <string.h>
#include <i386.h>
#include <syscalls.h>
#include <tipos.h>
#include <fs.h>

#define print(s) write(cd, s, str_len(s))

int str_len(const char *str) {
	int i;
	for (i = 0; str[i] != '\0'; i++);
	return i;
}

int main(void) {

	FILE_DESC cd, pipes[2];

	char buffer[16];

	cd = open("/console", FS_OPEN_RDWR); 

	write(cd, "TAREA 2!\n", 9);

	pipe(pipes);

	if (!pipes[0] || !pipes[1]) {
		print("Error al crear el pipe\n");
	}

	buffer[0] = 'A';
	buffer[1] = 'B';
	buffer[2] = 'C';
	write(pipes[1], buffer, 3);
 	
	buffer[0] = 'X';
	buffer[1] = 'X';
	buffer[2] = 'X';

	//flush(pipes[1]);

	read(pipes[0], buffer, 3);

	buffer[4] = '\0';
	print(buffer);
	print("\n");
	print("- Precione una tecla para cerrar la tarea -");
	read(cd, buffer, 1);

	flush(cd);

	exit();

	return 0;
}
